package net.wangds.auth.resource.ctrl;

import net.wangds.auth.resource.comp.GeneralResourceComp;
import net.wangds.auth.resource.entity.GeneralResourceEntity;
import net.wangds.jpa.Sorts;
import net.wangds.jpa.comp.AbstractRemovedComp;
import net.wangds.jpa.ctrl.AbstractJpaCompCtrl;
import net.wangds.web.entrypoint.BaseMultipleResp;
import net.wangds.web.entrypoint.PagingForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/auth/resource")
public class ResourceCtrl extends  AbstractJpaCompCtrl<GeneralResourceEntity>  {

    @Autowired
    private GeneralResourceComp mmCmpRes;
    @Override
    protected AbstractRemovedComp<GeneralResourceEntity> fetchJpaComp() {
        return mmCmpRes;
    }

    @Override
    protected BaseMultipleResp<GeneralResourceEntity> listWithKeywords(PagingForm page) {
        return mmConvPage2Resp.convert(mmCmpRes.findByKeywords(page.getKeywords(), mmConvPf2Pr.convert(page)));
    }


    @RequestMapping(value="/all", method = RequestMethod.POST)
    public BaseMultipleResp<GeneralResourceEntity> all(){
        return BaseMultipleResp.list(fetchJpaComp().findAll(Sorts.createTm_asc));
    }


}
